"use strict";
cc._RF.push(module, 'e324atel75NA5lL+TwtstU9', 'GameEnd');
// scripts/GameEnd.ts

Object.defineProperty(exports, "__esModule", { value: true });
var Model_1 = require("./Model");
var WxUtil_1 = require("./WxUtil");
var Config_1 = require("./Config");
var wx = window['wx'];
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var GameEnd = /** @class */ (function (_super) {
    __extends(GameEnd, _super);
    function GameEnd() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.winNode = null;
        _this.loseNode = null;
        _this.topNode = null;
        _this.stars = [];
        _this.eff = null;
        _this.endParticle = null;
        _this.starAudios = [];
        return _this;
    }
    GameEnd.prototype.onLoad = function () {
        this.winNode.active = Model_1.default.game.win;
        this.loseNode.active = !Model_1.default.game.win;
        this.topNode.getChildByName('success').active = Model_1.default.game.win;
        this.topNode.getChildByName('failed').active = !Model_1.default.game.win;
        //动态调整top位置
        var size = cc.view.getVisibleSize();
        if (size.height / size.width > 2) {
            this.topNode.getComponent(cc.Widget).top = 160;
        }
        else {
            this.topNode.getComponent(cc.Widget).top = 110;
        }
        if (!Model_1.default.game.win) {
            this.eff.active = true;
            var fade = cc.fadeOut(1);
            var call = cc.callFunc(this.onEffend, this);
            var seq = cc.sequence(fade, call);
            this.eff.runAction(seq);
        }
        if (WxUtil_1.default.gridAdLoaded) {
            WxUtil_1.default.showGridAd();
        }
        else {
            WxUtil_1.default.showBanner();
        }
    };
    GameEnd.prototype.onEffend = function () {
        this.eff.active = false;
    };
    GameEnd.prototype.start = function () {
        if (Model_1.default.game.selectedModel != 4) {
            this.topNode.getChildByName('star1').active = false;
            this.topNode.getChildByName('star2').active = false;
            this.topNode.getChildByName('star3').active = false;
            this.topNode.getChildByName('stargray').active = false;
            return;
        }
        if (!Model_1.default.game.win)
            return;
        if (Model_1.default.game.selectedLevel % 2 == 0) {
            WxUtil_1.default.showInterstitialAd();
        }
        var getStar = Model_1.default.game.getStar;
        for (var i = 0; i < getStar; i++) {
            var star = this.stars[i];
            star.active = true;
            star.scale = 4;
            star.opacity = 0;
            var t = i * 0.3 + 0.3;
            var delay = cc.delayTime(t);
            var scale = cc.scaleTo(0.5, 1, 1).easing(cc.easeBackOut());
            var seq = cc.sequence(delay, scale);
            star.runAction(seq);
            var delay2 = delay.clone();
            var fade = cc.fadeIn(0.3);
            var call = cc.callFunc(this.creatExpEffect, this, [i, star.x, star.y]);
            star.runAction(cc.sequence(delay2, fade, call));
        }
        //提交分数
        var starC = 0;
        for (var i = 0; i < Model_1.default.game.drawLevelInfo.length; i++) {
            if (Model_1.default.game.drawLevelInfo[i] > 0)
                starC += Model_1.default.game.drawLevelInfo[i];
        }
        if (typeof wx === 'undefined') {
            return;
        }
        // 发送结算分数到开放域
        wx.getOpenDataContext().postMessage({
            message: starC
        });
    };
    GameEnd.prototype.creatExpEffect = function (obj, data) {
        // this.particles[data[0]].resetSystem();
        var particle = cc.instantiate(this.endParticle);
        particle.getComponent(cc.ParticleSystem).resetSystem();
        particle.x = data[1];
        particle.y = data[2];
        this.node.getChildByName('top').addChild(particle);
        cc.audioEngine.playEffect(this.starAudios[data[0]], false);
    };
    GameEnd.prototype.next = function () {
        if (Model_1.default.game.selectedModel == 1) {
            if (Model_1.default.game.selectedLevel >= Config_1.default.preciseLevels.length - 1)
                cc.director.loadScene('menu');
            else {
                Model_1.default.game.selectedLevel++;
                cc.director.loadScene('game');
            }
        }
        else if (Model_1.default.game.selectedModel == 2) {
            // console.log(Model.game.selectedLevel, Config.brickLevels.length - 1)
            if (Model_1.default.game.selectedLevel >= Config_1.default.brickLevels.length - 1)
                cc.director.loadScene('menu');
            else {
                Model_1.default.game.selectedLevel++;
                cc.director.loadScene('gameDrop');
            }
        }
        else if (Model_1.default.game.selectedModel == 3) {
            if (Model_1.default.game.selectedLevel >= Config_1.default.dragLevels.length - 1)
                cc.director.loadScene('menu');
            else {
                Model_1.default.game.selectedLevel++;
                cc.director.loadScene('gameDrag');
            }
        }
        else if (Model_1.default.game.selectedModel == 4) {
            //console.log(Model.game.selectedLevel, Config.drawLevels.length - 1)
            if (Model_1.default.game.selectedLevel >= Config_1.default.drawLevels.length - 1)
                cc.director.loadScene('menu');
            else {
                Model_1.default.game.selectedLevel++;
                cc.director.loadScene('gameDraw');
            }
        }
    };
    GameEnd.prototype.retry = function () {
        if (Model_1.default.game.selectedModel == 1) {
            if (Model_1.default.game.selectedLevel >= Config_1.default.preciseLevels.length - 1)
                cc.director.loadScene('menu');
            else {
                cc.director.loadScene('game');
            }
        }
        else if (Model_1.default.game.selectedModel == 2) {
            // console.log(Model.game.selectedLevel, Config.brickLevels.length - 1)
            if (Model_1.default.game.selectedLevel >= Config_1.default.brickLevels.length - 1)
                cc.director.loadScene('menu');
            else {
                cc.director.loadScene('gameDrop');
            }
        }
        else if (Model_1.default.game.selectedModel == 3) {
            if (Model_1.default.game.selectedLevel >= Config_1.default.dragLevels.length - 1)
                cc.director.loadScene('menu');
            else
                cc.director.loadScene('gameDrag');
        }
        else if (Model_1.default.game.selectedModel == 4) {
            //console.log(Model.game.selectedLevel, Config.drawLevels.length - 1)
            if (Model_1.default.game.selectedLevel >= Config_1.default.drawLevels.length - 1)
                cc.director.loadScene('menu');
            else {
                cc.director.loadScene('gameDraw');
            }
        }
    };
    GameEnd.prototype.share = function () {
        WxUtil_1.default.share();
    };
    GameEnd.prototype.onXmxxClick = function () {
        WxUtil_1.default.jump("wxdb956f27b88772cc");
    };
    GameEnd.prototype.onZumaClick = function () {
        WxUtil_1.default.jump("wx6dac4c6e1e91c454");
    };
    GameEnd.prototype.onSuduClick = function () {
        WxUtil_1.default.jump("wxa45ec57d5717db87");
    };
    GameEnd.prototype.onBrickClick = function () {
        WxUtil_1.default.jump("wx570fee9777848176");
    };
    GameEnd.prototype.onBackClick = function () {
        cc.director.loadScene('menu');
    };
    // update (dt) {}
    GameEnd.prototype.onDestroy = function () {
        WxUtil_1.default.destroyBanner();
        WxUtil_1.default.destroyGrid();
    };
    __decorate([
        property(cc.Node)
    ], GameEnd.prototype, "winNode", void 0);
    __decorate([
        property(cc.Node)
    ], GameEnd.prototype, "loseNode", void 0);
    __decorate([
        property(cc.Node)
    ], GameEnd.prototype, "topNode", void 0);
    __decorate([
        property([cc.Node])
    ], GameEnd.prototype, "stars", void 0);
    __decorate([
        property(cc.Node)
    ], GameEnd.prototype, "eff", void 0);
    __decorate([
        property(cc.Prefab)
    ], GameEnd.prototype, "endParticle", void 0);
    __decorate([
        property({
            type: [cc.AudioClip]
        })
    ], GameEnd.prototype, "starAudios", void 0);
    GameEnd = __decorate([
        ccclass
    ], GameEnd);
    return GameEnd;
}(cc.Component));
exports.default = GameEnd;

cc._RF.pop();